package com.byx.chatclient.im;

import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;

import com.byx.chatclient.R;
import com.byx.chatclient.entity.message.Message;
import com.byx.chatclient.entity.message.TextMsgBody;
import com.byx.chatclient.utils.NotificationUtil;
import com.byx.chatclient.view.activity.GroupChatActivity;
import com.byx.chatclient.view.activity.SingleChatActivity;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

/**
 * MessageNotification
 *
 * @author Superb
 * @date 2021/4/21 23:08
 */
public class MessageNotification {

    public static void notification(Context context,Message message,boolean isSingleChat){
        String simpleMsg = message.getSenderNickName() + ":";
        switch (message.getMsgType()){
            case FILE:
                simpleMsg += "[文件]";
                break;
            case TEXT:
                simpleMsg += ((TextMsgBody) message.getBody()).getMessage();
                break;
            case AUDIO:
                simpleMsg += "[语音]";
                break;
            case IMAGE:
                simpleMsg += "[图片]";
                break;
            case VIDEO:
                simpleMsg += "[视频]";
                break;
            default:break;
        }
        String title = message.getSenderId();
        Intent intent;
        if (isSingleChat){
            intent = new Intent(context, SingleChatActivity.class);
        }else {
            intent = new Intent(context, GroupChatActivity.class);
        }
        PendingIntent pendingIntent = PendingIntent.getActivity(
                context,0,intent,PendingIntent.FLAG_UPDATE_CURRENT
        );
        NotificationUtil.getInstance(context)
                .setOngoing(true)
                .setContentIntent(pendingIntent)
                .setTicker("新消息")
                .setSound(android.provider.Settings.System.DEFAULT_NOTIFICATION_URI)
                .setPriority(NotificationManager.IMPORTANCE_HIGH)
                .sendNotification(1,title, simpleMsg, R.mipmap.ic_app_logo);
    }
}
